/*
 * lab14n1.c
 * Simple thread example
 */
#include <stdio.h>
#include <stdlib.h>
#include <sched.h>
 
#define CHILDSTACKSIZE 16384 


int x; 

 int threadtask1(void* in) { 
    x = x + 3; 
    printf("   Task1: x =   %d\n", x); flush();
 } 

int main(void) 
{ 
   // Set up stack for the threads 
   void* child_stack; 
   void* child_stackTop; 
   int child_id; 
   child_stack = (void *) malloc(CHILDSTACKSIZE); 
   child_stackTop = child_stack + CHILDSTACKSIZE; 
   x = 0; 
   printf("  Main: x = %d\n",x); flush();
   child_id = clone(threadtask1, child_stackTop, CLONE_VM, NULL); 
   printf("  Main: x = %d\n",x); flush();
} 
